Skip to content

Conversation

@knthm
Copy link
Contributor

@knthm knthm commented Jun 13, 2023

This PR adds device reinitialization for SPI and UART, as these will lose their hardware configuration when certain SoC series enter certain STOP/Standby modes.

Unfortunately, I've had to remove ADC and I2C reinit from this PR, as they require deeper PM work, seeing how they need to block during reinit process.

Depends on commits from PRs

References

See RM0461, chapter 5.4 - Low-Power Modes, Table 37, and chapter 5.4.9 - Stop 2 Mode:

  1. RM0461 Reference manual - STM32WLEx advanced Arm-based 32-bit MCUs with sub-GHz radio solution

@zephyrbot zephyrbot added area: Devicetree Binding PR modifies or adds a Device Tree binding platform: STM32 ST Micro STM32 area: SPI SPI bus area: I2C area: ADC Analog-to-Digital Converter (ADC) area: UART Universal Asynchronous Receiver-Transmitter labels Jun 13, 2023
@erwango erwango requested a review from ceolin June 13, 2023 14:53
Copy link
Member

@erwango erwango left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking a stab at this!

Initial "tires kicking" review. Great work but there are some points I'd like to refine or discuss, specially the integration with PM framework (adding @ceolin to the review for this specific part). Anyway, this goes in the good direction.

@knthm knthm force-pushed the stm32wl-power-save-fixes branch from 7f6bfc7 to 51278cf Compare June 13, 2023 16:23
@knthm
Copy link
Contributor Author

knthm commented Jun 13, 2023

  • Uncomment commented code left over from development & testing which was flagged by compliance checks
  • Rebase on main

@knthm knthm force-pushed the stm32wl-power-save-fixes branch 2 times, most recently from aad91dc to 89dabae Compare June 16, 2023 22:11
@knthm
Copy link
Contributor Author

knthm commented Jun 16, 2023

  • Add uart_config struct to persist runtime application/subsystem initialized UART parameters
  • Consolidate UART parameter configuration between driver instance (re-)init and runtime configuration execution flows
  • Additional uart_stm32 refactoring (See here for more details)

@knthm knthm force-pushed the stm32wl-power-save-fixes branch from 89dabae to f222c2b Compare June 18, 2023 22:20
@knthm
Copy link
Contributor Author

knthm commented Jun 18, 2023

  • Fix macro indentation in uart_stm32.c
  • Move reinit-power-states property to base/pm DT binding
  • Fix corner-case of pm_policy_state_lock_ call generation macro for when a power-state's substate-id isn't set

@zephyrbot zephyrbot added the area: Devicetree Binding PR modifies or adds a Device Tree binding label Aug 25, 2023
@zephyrbot zephyrbot requested a review from teburd August 25, 2023 12:23
@knthm knthm requested review from erwango and gmarull August 28, 2023 12:28
Add bit field values for specifying PM state transition direction, e.g.
state entry, exit, or both; use these in place of entering_state bool.

Move exising and add new pm_state_notify calls to the exact edges of
state transitions, to provide more flexibility and cover more use
cases.

Signed-off-by: Kenneth J. Miller <[email protected]>
Add pmstates array generated from global power-states DT node children,
vs. current per-CPU only pmstates array (SMP platforms only).

Add helper functions for retrieving the index of a global/per-CPU
power-state array element.
These functions are intended to faciliate easier processing of similar
PM data structures generated from the same DT power-states nodes.

Signed-off-by: Kenneth J. Miller <[email protected]>
Replace individual entry and exit callbacks with a singular callback,
with a separate direction bit field to indicate whether the struct
applies to state entry/exit, or both.

Add a void pointer to provide optional context for the callback.

Replace the singular pm_notifiers slist with individual power state-
specific slists, generated from DT power-states definitions on SMP, and
cpu-power-states on single-CPU platforms.

Un/register functions now take a power (sub)state as a parameter, in
addition to the usual pm_notifier struct; used to place the notifier
into the correct list.

Signed-off-by: Kenneth J. Miller <[email protected]>
Update pm tests and sample that make use of pm_notifier functionality,
or test system power state transitions.

Signed-off-by: Kenneth J. Miller <[email protected]>
This property allows defining one or more power-states phandles in which
a peripheral loses its configuration, and must be reinitialized.

States below and including S2RAM are inherently assumed to require
reinit, this property is intended to cover the exceptions outside
of this common use case.

It is intended to assist drivers in preventing the SoC from entering
these power states during critical code sections, as well as indicate
to power management services when a peripheral needs reinitialization.

Signed-off-by: Kenneth J. Miller <[email protected]>
Add general purpose of and example use-case of the reinit-power-states
property added in this commit series.

Signed-off-by: Kenneth J. Miller <[email protected]>
Add helper macros for building a pm_state_info array from a device's
reinit-power-states.

These macros are intended to assist drivers in and around device
reinitializiation.

Signed-off-by: Kenneth J. Miller <[email protected]>
@knthm knthm force-pushed the stm32wl-power-save-fixes branch from e0269b3 to 776f6ec Compare September 2, 2023 12:44
The added reinitialization function helps PM logic restore peripheral
functionality when clock context and register contents are lost in
certain low-power modes.

Signed-off-by: Kenneth J. Miller <[email protected]>
Refactor to prevent code duplication in the driver reinitialization
functionality following this commit.

Move HAL include statement from driver source to header to make header
self-contained.

Signed-off-by: Kenneth J. Miller <[email protected]>
The added reinitialization feature helps PM logic restore bus
functionality when clock context is lost in certain low-power modes.

Signed-off-by: Kenneth J. Miller <[email protected]>
Enable STOP2 reinitialization for affected USART and SPI peripheral
instances, as these will otherwise be INOP when the SoC returns from
STOP2 low-power mode.

Signed-off-by: Kenneth J. Miller <[email protected]>
@erwango
Copy link
Member

erwango commented Sep 27, 2023

@ceolin How do you feel globally about this PR ?

I'm willing to approve #59200, but this will be deadcode if #60998 never gets in.

@ceolin
Copy link
Member

ceolin commented Sep 27, 2023

@ceolin How do you feel globally about this PR ?

I'm willing to approve #59200, but this will be deadcode if #60998 never gets in.

@erwango it seems that the notifier changes is replicated in all prs (#59200, #61680 and #60998). Will focus the review first in #60998 that is base for all of them.

@github-actions
Copy link

This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time.

@github-actions github-actions bot added the Stale label Nov 27, 2023
@github-actions github-actions bot closed this Dec 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Power Management area: SPI SPI bus area: UART Universal Asynchronous Receiver-Transmitter platform: STM32 ST Micro STM32 Stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants